package com.example.myapplication.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.myapplication.R;

/**
 * created by moxun on 2022/5/6
 * moxun@zhuangdianwenhua.com
 */
public class ImageListAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    public ImageListAdapter() {
        super(R.layout.item_image_list);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, String s) {
        ImageView ivImage = (ImageView) baseViewHolder.getView(R.id.iv_image);

        setSize(ivImage);

        Glide.with(getContext())
                .load(s)
                .centerCrop()
                .into(ivImage);

//        ImageLoader.show(
//                ImageLoader.Builder.withString(getContext(), s)
//                        .noPlaceholderAndError()
//                        .build(), ivImage
//        );
        ivImage.setTransitionName(s);
    }

    protected void setSize(View view) {
        int width = (view.getResources().getDisplayMetrics().widthPixels) / 3;
        int height = width;//(int) (mData.height / (float) mData.width * width);
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.height = height;
        view.setLayoutParams(layoutParams);
    }
}
